package jastgen.nodes;

public class Field {

	private final Type type;
	private final String name;
	private final String nameInMethod;
	private final String body;

	public Field(
			final Type type,
			final String name,
			final boolean capitalizeAll)
	{
		this(type, name, capitalizeAll, null);
	}

	public Field(
			final Type type,
			final String name,
			final boolean capitalizeAll,
			final String body)
	{
		this.type = type;
		this.name = name;
		this.nameInMethod =
			capitalizeAll
					? name.toUpperCase()
					: capitalize(name);
		this.body = body;
	}

	private static String capitalize(
			final String s)
	{
		return Character.toUpperCase(s.charAt(0)) + s.substring(1);
	}

	public Type getType() {
		return type;
	}

	public String getName() {
		return name;
	}

	public String getNameInMethod() {
		return nameInMethod;
	}

	public String getBody() {
		return body;
	}

	public boolean hasBody() {
		return body != null;
	}

	// trueだとequals、hashCode、compareToで無視される。
	// 現在はhasBodyと連動している。
	public boolean isIgnored() {
		return hasBody();
	}
}
